package cn.edu.stu.syllabus.adapters;

import android.content.Context;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;

import com.bigkoo.convenientbanner.holder.CBViewHolderCreator;
import com.bigkoo.convenientbanner.holder.Holder;

import butterknife.BindView;
import butterknife.ButterKnife;
import cn.edu.stu.syllabus.R;
import cn.edu.stu.syllabus.repository.banner.local.BannerEntry;
import cn.edu.stu.syllabus.params.ImageLoaderOptions;
import cn.edu.stu.syllabus.utils.ImageLoader;

/**
 * Created by liyujie on 2017/3/8.
 */

public class BannerImageHolderView implements Holder<BannerEntry> {

    @BindView(R.id.bannerImageView)
    ImageView mBannerImageView;

    Fragment mFragment;

    public BannerImageHolderView(Fragment fragment) {
        mFragment = fragment;
    }

    @Override
    public View createView(Context context) {
        View view = LayoutInflater.from(context).inflate(R.layout.item_banner, null, false);
        ButterKnife.bind(this, view);
        return view;
    }

    @Override
    public void UpdateUI(Context context, int position, BannerEntry data) {
        ImageLoaderOptions options = new ImageLoaderOptions();
        options.setErrorDrawable(R.drawable.banner_default);
        ImageLoader.loadImage(mFragment, mBannerImageView, data.getImgUrl(), options);
    }

    public static class BannerViewHolderCreator implements CBViewHolderCreator {

        private Fragment mFragment;

        public BannerViewHolderCreator(Fragment fragment) {
            mFragment = fragment;
        }

        @Override
        public Object createHolder() {
            return new BannerImageHolderView(mFragment);
        }
    }

    public static final int[] sIndicator = new int[]{R.drawable.ic_page_indicator,
            R.drawable.ic_page_indicator_focused};

}

